//package me.springboot.mybatis.exception;
//
//import me.springboot.mybatis.core.RetCode;
//import me.springboot.mybatis.core.RetResponse;
//import me.springboot.mybatis.core.RetResult;
//import org.springframework.validation.BindException;
//import org.springframework.validation.FieldError;
//import org.springframework.validation.ObjectError;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.servlet.config.annotation.EnableWebMvc;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//@RestController
//@ControllerAdvice
//@EnableWebMvc
//public class GlobalExceptionHandler {
//
//    @ExceptionHandler(BindException.class)
//    @ResponseBody
//    public RetResult jsonErrorHandler(HttpServletRequest req, BindException e) throws Exception {
//        List<Map<String, String>> errorList = new ArrayList<>();
//        for (ObjectError objectError : e.getBindingResult().getAllErrors()) {
//            Map<String, String> errorMap = new HashMap<>();
//            errorMap.put(((FieldError) objectError).getField(), objectError.getDefaultMessage());
//            errorList.add(errorMap);
//        }
//        Map<String, Object> error = new HashMap<>();
//        return RetResponse.makeRsp(RetCode.BUS_FALL.getCode(), "参数错误", errorList);
//    }
//
//    /*@ExceptionHandler(value = ResultException.class)
//    @ResponseBody
//    public Result resultExceptionHandler(HttpServletRequest req, Exception ex) throws Exception {
//        ResultException exception = (ResultException)ex;
//        NResult object = new NResult();
//        object.setCode(exception.getCode());
//        object.setMessage(exception.getMessage());
//        object.setData(null);
//        return new Result(true, object);
//    }*/
//}
